package cn.myfrank.mixin;

import net.minecraft.entity.player.HungerManager;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.world.Difficulty;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(HungerManager.class)
public abstract class MixinHungerManager {
    @Shadow private int foodLevel;
    @Shadow private float saturationLevel;
    @Shadow private float exhaustion;
    
    @Inject(method = "update",
            at = @At(value = "FIELD",target = "Lnet/minecraft/entity/player/HungerManager;exhaustion:F",ordinal = 1))
    public void method0(PlayerEntity player, CallbackInfo ci){
        Difficulty difficulty = player.getWorld().getDifficulty();
        if(difficulty == Difficulty.PEACEFUL && !(saturationLevel > 0.0F)){
            foodLevel = Math.max(foodLevel - 1, 1);
        }
    }
}
